#coding=utf-8

#!/usr/bin/env python
import settings
import MySQLdb,redis
from lib.config import *
def checksql(rt):
    r = redis.Redis(host=settings.redisinfo[0], port=settings.redisinfo[1], db=rt)
    t = r.keys()
    conn = MySQLdb.Connect(host=settings.mysqlinfo[0],user=settings.mysqlinfo[1],passwd=settings.mysqlinfo[2],db=settings.mysqlinfo[3],charset=settings.mysqlinfo[4],port=settings.mysqlinfo[5])
    for i in t:
        url = settings.ding_rule[[j['sid'] for j in settings.ding_rule].index(int(i[2:]))]['page']
        for k in r.smembers(i):
            c = conn.cursor()
            if c.execute("select id from ti_thread where url = '%s'"%(url % k)) ==0:
                print url % k
                r.srem(i,k)
                pass
            c.close()
    conn.close()
if __name__=='__main__':
    for i in settings.ding_rule:
        checksql(i['sid'])